package com.definesys.smecrailtransit.SmecManager.SmecRetrofit.Interceptor;

import com.definesys.smecrailtransit.SmecManager.SmecSession.SmecSession;
import com.definesys.smecrailtransit.service.LogService.AbnormalCollection;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by xupeizuo on 2017/7/27.
 */

public class TokenInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request().newBuilder()
                .addHeader("DF_KEY", SmecSession.getToken() == null ? "" : SmecSession.getToken())
                .build();
        Response response = null ;
        try {
            response = chain.proceed(request);
        } catch (Exception e) {
            e.printStackTrace();
            AbnormalCollection.getAbnormalCollection().saveExceptionMsg(e,AbnormalCollection.EXCEPTION_TYPE_THROW_E);
        }
        return response;
    }
}
